import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_application_1/components/lottie_refresh_header/lottie_refresh_header.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class LottieRefresh extends StatefulWidget {
  @override
  _LottieRefreshState createState() => _LottieRefreshState();
}

class _LottieRefreshState extends State<LottieRefresh> {
  RefreshController _controller = RefreshController();

  // 下拉刷新
  Future _onRefresh() async {
    await Future.delayed(Duration(milliseconds: 1500));
    _controller.refreshCompleted();
  }

  @override
  Widget build(BuildContext context) {
    return RefreshConfiguration(
      headerTriggerDistance: LottieRefreshHeader.size,
      child: SmartRefresher(
        controller: _controller,
        // 下拉刷新
        enablePullDown: true,
        onRefresh: _onRefresh,
        header: LottieRefreshHeader(),
        child: ListView.builder(
          itemBuilder: (BuildContext context, int index) {
            return ListTile(
              title: Text('item_$index'),
            );
          },
          itemCount: 30,
        ),
      ),
    );
  }
}
